package org.codefinger.json.parser.deserializer;

import java.math.BigDecimal;

import org.codefinger.json.parser.JSONArrayDeserializer;
import org.codefinger.json.parser.JSONDeserializer;
import org.codefinger.json.parser.JSONLexer;
import org.codefinger.json.parser.JSONObjectDeserializer;

public class DeserializerForBoolean implements JSONDeserializer {

	public static final DeserializerForBoolean	INSTANCE	= new DeserializerForBoolean();

	private DeserializerForBoolean() {

	}

	
	@Override
	public Object stringValue(String value) {
		return  Boolean.valueOf(value);
	}

	
	@Override
	public Object stringValue(JSONLexer jsonLexer) {
		return  Boolean.valueOf(jsonLexer.getOriginalString());
	}

	
	@Override
	public Object intValue(String value) {
		return  Boolean.valueOf(Integer.parseInt(value) != 0);
	}

	
	@Override
	public Object floatValue(String value) {
		return  Boolean.valueOf(new BigDecimal(value).intValue() != 0);
	}

	
	@Override
	public Object falseValue() {
		return  Boolean.FALSE;
	}

	
	@Override
	public Object trueValue() {
		return  Boolean.TRUE;
	}

	@Override
	public JSONArrayDeserializer createArrayDeserializer() {
		return ArrayDeserializerForNull.INSTANCE;
	}

	@Override
	public JSONObjectDeserializer createObjectDeserializer() {
		return ObjectDeserializerForNull.INSTANCE;
	}

}
